package com.jnu.mydiary.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.jnu.mydiary.R;
import com.jnu.mydiary.ShowActivity;
import com.jnu.mydiary.griditem.GridItems;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class ItemAdapter extends BaseAdapter  {

    private List<GridItems> GridItemsList;
    private LayoutInflater layoutInflater;
    public int selectPos=0;

    public ItemAdapter(Context context, List<GridItems> provinceBeanList) {
        this.GridItemsList = provinceBeanList;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return GridItemsList.size();
    }

    @Override
    public Object getItem(int position) {
        return GridItemsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return  position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.layout_grid_items, parent,false);
            holder = new ViewHolder();
            holder.text = convertView.findViewById(R.id.tv);
            holder.imageView = convertView.findViewById(R.id.iv);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        GridItems provinceBean = GridItemsList.get(position);
        if (provinceBean != null) {
            holder.text.setText(provinceBean.getName());
            holder.imageView.setImageResource(provinceBean.getPictureID());

        }


        return convertView;
    }


    class ViewHolder {
        TextView text;
        ImageView imageView;

    }


}
